<!--  -->
<template>
  <div class="operate-system-download-list dffr" v-if="system && system.id > 0">
    <el-button type="primary" @click="create">新建</el-button>
    <el-button type="success" @click="refresh">刷新</el-button>
    <el-button type="warning" @click="setup">系统设置</el-button>
    <el-button type="primary" class="refuse-btn" @click="refuse">回收站</el-button>
    <el-button type="primary" class="excel-btn" @click="importMultiple">批量导入</el-button>
    <DialogSystem />
    <!-- 选择资源文件 -->
    <ChooseRepertory ref="chooseRepertory" />
  </div>
</template>

<script>
import DialogSystem from '@/components/common/design/dialog/system/DialogSystem.vue'
import ChooseRepertory from '@/components/common/repertory/ChooseRepertory.vue'
import { getSystemItemPathBySystem, getSystemDownloadRefuseBySid } from '@/core/functions.js'
import * as WindowType from '@/config/windowtype.js'
import PubSub from 'pubsub-js'
export default {
  props: {
    resetData: {
      type: Function
    },
    system: {
      type: Object
    },
    resetGlobalLoading: {
      type: Function
    }
  },
  data () {
    return {
    }
  },
  methods: {
    create () {
      // 打开下载系统内容添加组件，并且需要带系统ID
      let fullPath = getSystemItemPathBySystem(this.system)
      if (!fullPath) {
        return
      }
      // 判断是否会话存储系统页码，有的话页码改为1
      let systbPageCurInfo = JSON.parse(sessionStorage.getItem('systbPageCur' + this.system.id))
      if (systbPageCurInfo) {
        sessionStorage.setItem('systbPageCur' + this.system.id, JSON.stringify({pageCur: 1, fromItem: false}))
      }
      this.$store.dispatch('navAppend', { path: fullPath })
    },
    refresh () {
      this.resetData()
    },
    setup () {
      PubSub.publish(WindowType.EDIT_DOWNLOAD_SYSTEM_CONFIG, {systemId: this.system.id, curpageName: false})
    },
    // 回收站
    refuse () {
      // 打开系统回收站，并且需要带系统ID
      let fullPath = getSystemDownloadRefuseBySid(this.system.id)
      if (!fullPath) {
        return
      }
      this.$store.dispatch('navAppend', { path: fullPath })
    },
    // 资源库批量导入
    importMultiple () {
      this.$refs['chooseRepertory'].show({ title: '选择文件', where: { type: [1] }, fixedCondition: { type: true }, max: 20 }, (repertoryList) => {
        if (repertoryList.length > 0) {
          this.resetGlobalLoading(true)
          let repertoryIds = []
          repertoryList.forEach(item => {
            repertoryIds.push(item.id)
          })
          // 导入信息系统数据
          this.$jpost('/system/download/repertory-import', { repertoryIds: repertoryIds, systemId: this.system.id }).then((resoponse) => {
            this.resetGlobalLoading(false)
            if (resoponse) {
              this.resetData()
            }
          })
        }
      })
    }
  },
  components: {
    DialogSystem,
    ChooseRepertory
  }
}

</script>
<style scoped lang="scss">
.refuse-btn{
  background: #2DB3FB;
  border-color:#2DB3FB;
  &:hover{
    background: #49BDFC;
    border-color:#49BDFC;
  }
}
.excel-btn{
  background: #8E8EFF;
  border-color:#8E8EFF;
  &:hover{
    background: #A2A2FF;
    border-color:#A2A2FF;
  }
}
</style>
